<script>
import outMain from "@/components/outMain.vue";
import { ElMessage, ElMessageBox } from "element-plus";
import { report, reportStatus } from "@/http/api";

export default {
  components: { outMain },
  name: "",
  data() {
    return {
      tableData: [],
      statusArr: [
        { label: "全部", value: "" },
        { label: "未处理", value: "1" },
        { label: "已处理", value: "2" },
        { label: "已忽略", value: "3" },
      ],
      queryData: {
        status: "",
        sup_notice_id: "",
        search: "",
        page: 1,
        per_page: 10,
      },
      total: 0,
    };
  },
  props: {},
  setup() {},
  methods: {
    detailFn(item) {
      let path = "";
      if (item.report_type == 1) {
        path = "/sendWorkDetail";
      } else if (item.report_type == 2) {
        path = "/sendTrainDetail";
      }
      this.$router.push({
        path: path,
        query: { id: item.report_content_id, page: this.queryData.page },
      });
    },
    checkStatusFn(row, type) {
      let str = type == 2 ? "已处理" : "已忽略";
      ElMessageBox.confirm(`确定选择的举报状态更为${str}吗?`, "操作提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        let data = {
          report_id: row.report_id,
          status: type,
        };
        reportStatus(data).then((res) => {
          if (res.data.code == 1) {
            ElMessage({
              type: "success",
              message: "操作成功",
            });
            this.getData();
          }
        });
      });
    },
    getData() {
      report(this.queryData).then((res) => {
        if (res.data.code == 1) {
          this.tableData = res.data.data.data;
          this.total = res.data.data.total;
        }
      });
    },
  },
  mounted() {},
  created() {
    this.queryData.page = Number(localStorage.getItem("boot_page")) || 1;

    this.queryData.account_id = this.$route.query.id || "";
    this.getData();
  },
};
</script>
<template>
  <outMain>
    <div class="tableCont">
      <div class="tableName flexCont">
        <div>举报列表（{{ total }}）</div>
      </div>
      <div class="tableSerch">
        <div class="serchLeft"></div>
        <div class="serchRight">
          <el-form class="flexCenter" :inline="true">
            <el-form-item>
              <el-select
                @change="getData"
                v-model="queryData.status"
                clearable
                placeholder="请选择状态"
              >
                <el-option
                  v-for="item in statusArr"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
            <btn value="搜索" @click="getData"></btn>
          </el-form>
        </div>
      </div>
      <el-table class="tableMain" :data="tableData" stripe style="width: 100%">
        <el-table-column
          prop="nick_name"
          show-overflow-tooltip
          label="用户账号"
        />
        <el-table-column
          prop="report_content_fbr"
          show-overflow-tooltip
          label="相关账号"
        />
        <el-table-column
          prop="report_content_name"
          show-overflow-tooltip
          width="150"
          label="相关帖子"
        />
        <el-table-column prop="type" show-overflow-tooltip label="举报类型">
          <template #default="{ row }">
            <el-tag v-if="row.report_type == 1">岗位举报</el-tag>
            <el-tag type="warning" v-if="row.report_type == 2">培训举报</el-tag>
            <el-tag type="danger" v-if="row.report_type == 3">广场举报</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          width="300"
          prop="report_content"
          show-overflow-tooltip
          label="举报内容"
        />
        <el-table-column show-overflow-tooltip label="账号状态">
          <template #default="{ row }">
            <div class="tagGroup">
              <el-tag v-if="row.status == 1">待处理</el-tag>
              <el-tag type="success" v-if="row.status == 2">已处理</el-tag>
              <el-tag type="info" v-if="row.status == 3">已忽略</el-tag>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="handle_time"
          show-overflow-tooltip
          label="处理时间"
        />
        <el-table-column
          prop="create_time"
          width="180"
          show-overflow-tooltip
          label="创建时间"
        />
        <el-table-column prop="Name" width="150" label="操作">
          <template #default="{ row }">
            <div class="tableCtrl">
              <div
                class="redText ctrlText"
                v-if="row.status == 1"
                @click="checkStatusFn(row, 3)"
              >
                忽略
              </div>
              <div
                class="blueText ctrlText"
                v-if="row.status == 1"
                @click="checkStatusFn(row, 2)"
              >
                已处理
              </div>
              <div
                class="greenText ctrlText"
                v-if="row.report_type != 3"
                @click="detailFn(row)"
              >
                详情
              </div>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="pageCont">
        <el-pagination
          v-model:currentPage="queryData.page"
          v-model:page-size="queryData.per_page"
          background
          layout="total, prev, pager, next, jumper"
          :total="total"
          @size-change="getData"
          @current-change="getData"
        />
      </div>
    </div>
  </outMain>
</template>
<style scoped lang="less"></style>
